home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / wb-tools / toolmanager / source / library / accessobj.c next >
C/C++ Source or Header  |  1994-06-06  |  7KB  |  247 lines

  1. /*
  2.  * accessobj.c  V2.1
  3.  *
  4.  * TMObject, Type: Access
  5.  *
  6.  * (c) 1990-1993 Stefan Becker
  7.  */
  8.  
  9. #include "ToolManagerLib.h"
  10.  
  11. /* Node for one Exec object */
  12. struct AccessEntry {
  13.                     struct AccessEntry *ae_Next;
  14.                     char               *ae_ExecName;
  15.                     struct TMLink      *ae_ExecLink;
  16.                    };
  17.  
  18. /* extended TMObject structure for TMOBJTYPE_MENU objects */
  19. struct TMObjectAccess {
  20.                        struct TMObject     ac_Object;
  21.                        struct AccessEntry *ac_Entries;
  22.                       };
  23.  
  24. /* Create an Access object */
  25. struct TMObject *CreateTMObjectAccess(struct TMHandle *handle, char *name,
  26.                                       struct TagItem *tags)
  27. {
  28.  /* Network installed? */
  29.  if (LocalEntity) {
  30.   struct TMObjectAccess *tmobj;
  31.  
  32.   /* allocate memory for object */
  33.   if (tmobj=(struct TMObjectAccess *)
  34.              AllocateTMObject(sizeof(struct TMObjectAccess))) {
  35.    struct TagItem *ti,*tstate;
  36.    struct AccessEntry *ae=NULL;
  37.  
  38.    /* Scan tag list */
  39.    tstate=tags;
  40.    while (ti=NextTagItem(&tstate)) {
  41.  
  42.     DEBUG_PRINTF("Got Tag (0x%08lx)\n",ti->ti_Tag);
  43.  
  44.     switch (ti->ti_Tag) {
  45.      case TMOP_Exec: if (ti->ti_Data) {
  46.                       struct AccessEntry *newae;
  47.  
  48.                       /* Alloc AccessEntry structure */
  49.                       if (newae=AllocMem(sizeof(struct AccessEntry),
  50.                                          MEMF_CLEAR)) {
  51.                        /* Set name */
  52.                        newae->ae_ExecName=(char *) ti->ti_Data;
  53.  
  54.                        /* Add link to Exec object */
  55.                        newae->ae_ExecLink=AddLinkTMObject(handle,
  56.                                                           (char *) ti->ti_Data,
  57.                                                           TMOBJTYPE_EXEC,
  58.                                                           (struct TMObject *)
  59.                                                            tmobj);
  60.  
  61.                        DEBUG_PRINTF("ExecLink: 0x%08lx\n",newae->ae_ExecLink);
  62.  
  63.                        /* Add node to list. Head of list? */
  64.                        if (ae) {
  65.                         /* No. Add to tail */
  66.                         ae->ae_Next=newae;
  67.                         ae=newae;
  68.                        } else {
  69.                         /* Yes. Init list anchor */
  70.                         tmobj->ac_Entries=newae;
  71.                         ae=newae;
  72.                        }
  73.                       }
  74.                      }
  75.                      break;
  76.     }
  77.    }
  78.  
  79.    /* All OK */
  80.    return(tmobj);
  81.   }
  82.  }
  83.  /* call failed */
  84.  return(NULL);
  85. }
  86.  
  87. /* Delete an Access object */
  88. BOOL DeleteTMObjectAccess(struct TMObjectAccess *tmobj)
  89. {
  90.  struct AccessEntry *ae,*nextae=tmobj->ac_Entries;
  91.  
  92.  DEBUG_PRINTF("Delete/Access (0x%08lx)\n",tmobj);
  93.  
  94.  /* Remove entries */
  95.  while (ae=nextae) {
  96.   /* Get pointer to next entry */
  97.   nextae=ae->ae_Next;
  98.  
  99.   /* Remove link */
  100.   if (ae->ae_ExecLink) RemLinkTMObject(ae->ae_ExecLink);
  101.  
  102.   /* Free entry */
  103.   FreeMem(ae,sizeof(struct AccessEntry));
  104.  }
  105.  
  106.  /* Remove object from list */
  107.  Remove((struct Node *) tmobj);
  108.  
  109.  /* Free object */
  110.  FreeMem(tmobj,sizeof(struct TMObjectAccess));
  111.  
  112.  /* All OK. */
  113.  return(TRUE);
  114. }
  115.  
  116. /* Change an Access object */
  117. struct TMObject *ChangeTMObjectAccess(struct TMHandle *handle,
  118.                                       struct TMObjectAccess *tmobj,
  119.                                       struct TagItem *tags)
  120. {
  121.  struct TagItem *ti,*tstate;
  122.  struct AccessEntry *ae=tmobj->ac_Entries;
  123.  
  124.  /* Search last AccessEntry */
  125.  if (ae)
  126.   while (ae->ae_Next) ae=ae->ae_Next;
  127.  
  128.  /* Scan tag list */
  129.  tstate=tags;
  130.  while (ti=NextTagItem(&tstate)) {
  131.  
  132.   DEBUG_PRINTF("Got Tag (0x%08lx)\n",ti->ti_Tag);
  133.  
  134.   switch (ti->ti_Tag) {
  135.    case TMOP_Exec: if (ti->ti_Data) {
  136.                     struct AccessEntry *newae;
  137.  
  138.                     /* Alloc AccessEntry structure */
  139.                     if (newae=AllocMem(sizeof(struct AccessEntry),
  140.                                        MEMF_CLEAR)) {
  141.                      /* Set name */
  142.                      newae->ae_ExecName=(char *) ti->ti_Data;
  143.  
  144.                      /* Add link to Exec object */
  145.                      newae->ae_ExecLink=AddLinkTMObject(handle,
  146.                                                         (char *) ti->ti_Data,
  147.                                                         TMOBJTYPE_EXEC,
  148.                                                         (struct TMObject *)
  149.                                                          tmobj);
  150.  
  151.                      /* Add node to list. Head of list? */
  152.                      if (ae) {
  153.                       /* No. Add to tail */
  154.                       ae->ae_Next=newae;
  155.                       ae=newae;
  156.                      } else {
  157.                       /* Yes. Init list anchor */
  158.                       tmobj->ac_Entries=newae;
  159.                       ae=newae;
  160.                      }
  161.                     }
  162.                    }
  163.                    break;
  164.   }
  165.  }
  166.  
  167.  /* All OK. */
  168.  return(TRUE);
  169. }
  170.  
  171. /* Allocate & Initialize a TMLink structure */
  172. struct TMLink *AllocLinkTMObjectAccess(struct TMObjectAccess *tmobj)
  173. {
  174.  struct TMLink *tml;
  175.  
  176.  /* Allocate memory for link structure */
  177.  if (tml=AllocMem(sizeof(struct TMLink),MEMF_CLEAR|MEMF_PUBLIC))
  178.   /* Initialize link structure */
  179.   tml->tml_Size=sizeof(struct TMLink);
  180.  
  181.  return(tml);
  182. }
  183.  
  184. /* Update link structures */
  185. void DeleteLinkTMObjectAccess(struct TMLink *tml)
  186. {
  187.  struct TMObjectAccess *tmobj=(struct TMObjectAccess *) tml->tml_LinkedTo;
  188.  struct AccessEntry *ae=tmobj->ac_Entries;
  189.  
  190.  /* Scan tool list */
  191.  while (ae) {
  192.   /* Link to Exec object? */
  193.   if (tml==ae->ae_ExecLink) {
  194.    ae->ae_ExecLink=NULL;
  195.    break;
  196.   }
  197.  
  198.   /* Get pointer to next tool */
  199.   ae=ae->ae_Next;
  200.  }
  201. }
  202.  
  203. /* Activate an Access object */
  204. void ActivateTMObjectAccess(struct TMLink *tml, char *execname)
  205. {
  206.  struct TMObjectAccess *tmobj=(struct TMObjectAccess *) tml->tml_Linked;
  207.  struct AccessEntry *ae;
  208.  
  209.  DEBUG_PRINTF("Activate/Access '%s'\n",execname);
  210.  
  211.  /* Access check disabled? */
  212.  if (ae=tmobj->ac_Entries)
  213.  
  214.   /* No, search Exec object in access list */
  215.   while (ae) {
  216.    /* Exec object found? */
  217.    if (!strcmp(execname,ae->ae_ExecName)) {
  218.     /* Yes! If link is valid, activate object */
  219.     if (ae->ae_ExecLink) CallActivateTMObject(ae->ae_ExecLink,NULL);
  220.  
  221.     /* Leave loop */
  222.     break;
  223.    }
  224.  
  225.    /* Get pointer to next node */
  226.    ae=ae->ae_Next;
  227.   }
  228.  else {
  229.   /* Yes, free access granted */
  230.   struct TMLink *tmle;
  231.  
  232.   DEBUG_PRINTF("Free access!\n");
  233.  
  234.   /* Search Exec object (only global Exec objects can be activated!) */
  235.   if (tmle=AddLinkTMObject(PrivateTMHandle,execname,TMOBJTYPE_EXEC,NULL)) {
  236.  
  237.    DEBUG_PRINTF("Link: 0x%08lx\n",tmle);
  238.  
  239.    /* Activate Exec object */
  240.    CallActivateTMObject(tmle,NULL);
  241.  
  242.    /* Remove link */
  243.    RemLinkTMObject(tmle);
  244.   }
  245.  }
  246. }
  247.